import { defineStore } from 'pinia'
export const useStaffStore = defineStore(
  'staff', 
  {
    state: () => ({      
      token: localStorage.getItem('token'),
      staff: localStorage.getItem('staff'),
      username: localStorage.getItem('username')
    }),
    //persist: {
    //  enabled: true, // 开启数据持久化
    //  strategies: [
        //{ key: 'token', storage: localStorage}, // 指定存储键和存储方式为localStorage
        //{ key: 'staff', storage: localStorage},
    //    { storage: localStorage ,paths: ['token', 'staff', 'username']}
    //  ]
    //},
    persist:[
      { key: 'token', storage: localStorage},
      { key: 'staff', storage: localStorage},
      { key: 'username', storage: localStorage}
    ],
    actions: {
      setToken(token: string) {     
        this.token = token
      },
      setStaff(staff: string) {
        this.staff = staff
      },
      setUsername(username: string) {
        this.username = username
      },
      logOut() {
        this.token = ''
        this.staff = null
        this.username = null
      }
    }
  }
)